package parser;

public class TFIDF {
	
        private Number numOfOccurrences;
        private Number totalTermsInParagraph;
        private Number totalParagraphs;
        private Number numOfParagraphsWithTerm;
        
        public TFIDF(Number occ, Number totTerms, Number totParas, Number parasWithTerms) {
            numOfOccurrences = occ;
            totalTermsInParagraph = totTerms;
            totalParagraphs = totParas;
            numOfParagraphsWithTerm = parasWithTerms;
        }
        
        /**
         * Calculates the tf-idf value of the current term. 
         * 
         * @return the float value of the tf-idf.
         */
        public Float getValue(){
        		
    		// Float.MIN_VALUE permet d'éviter d'avoir une division par zéro
    	
        	// TODO Optimiser calcul de idf (cf cours)
        	
            float tf = numOfOccurrences.floatValue() / (Float.MIN_VALUE + totalTermsInParagraph.floatValue());
            float idf = (float) Math.log10(totalParagraphs.floatValue() / (Float.MIN_VALUE + numOfParagraphsWithTerm.floatValue()));
            
            return (tf * idf);
        }
}